package com.jdk.learn.juc2.atomic;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 类功能描述:
 *
 * @author bgt
 * @version V1.0
 * @since 2019-02-14 10:36
 */
public class AtomicLongDemo {
    private static boolean flag;
    //计数器
    private static volatile AtomicLong count=new AtomicLong();
    // 数组1
    private static Integer[] array1=new Integer[]{10,0,2,0,4,0,5,6};
    // 数组2
    private static Integer[] array2=new Integer[]{10,1,2,0,4,0,5,0,3,0,9,1};
    public static void main(String[] args) throws InterruptedException {
        System.out.println(flag);
        Thread thread1=new Thread(()->{
            for (int i=0;i<array1.length;i++){
                if (array1[i].intValue()==0){
                    count.incrementAndGet();
                }
            }
        });
        Thread thread2=new Thread(()->{
            for (int i=0;i<array2.length;i++){
                if (array2[i].intValue()==0){
                    count.incrementAndGet();
                }
            }
        });

        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println("0的数量是:"+count.get());
    }
}
